package wp.wf.com.myapplication.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import junit.framework.Test;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

import wp.wf.com.myapplication.R;
import wp.wf.com.myapplication.fragment.OneFragment;
import wp.wf.com.myapplication.myinterface.CallBack;

@ContentView(R.layout.activity_main)
public class MainActivity extends BaseActivity implements CallBack<Test> {
    @ViewInject(R.id.vp)
    private ViewPager vp;
    @ViewInject(R.id.toolbar)
    private Toolbar toolbar;
    @ViewInject(R.id.tabLayou)
    private TabLayout tl;
    private List<Fragment> fragmentDatas;
    private List<String> fragmentTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setSupportActionBar(toolbar);
        fragmentDatas = new ArrayList<>();
        fragmentTitle = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Bundle bundle = new Bundle();
            bundle.putString("data", i + "");
            OneFragment fragment_test = new OneFragment();
            fragment_test.setArguments(bundle);
            fragmentDatas.add(fragment_test);
            fragmentTitle.add("TAB" + i);
        }
        MyFragmentAdapter adapter = new MyFragmentAdapter(getSupportFragmentManager());
        vp.setAdapter(adapter);
        tl.setupWithViewPager(vp);
    }


    @Override
    void setParams() {

    }

    @Override
    public void onFinish(String dataString) {

    }

    @Override
    public void onSuccess(Test test) {

    }

    @Override
    public void onError(String dataError) {

    }

    class MyFragmentAdapter extends FragmentPagerAdapter {

        public MyFragmentAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentDatas.get(position);
        }

        @Override
        public int getCount() {
            return fragmentDatas.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return fragmentTitle.get(position);
        }
    }


}
